﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//using System.Web.Mail;
using System.Net.Mail;
using WebUI.Model;
using System.Text;

namespace WebUI.Controllers
{
    public class ContactController : Controller
    {
        private void SendEmailToClient(Contact contact)
        {
            try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress("info@tapfreaks.net");
                message.To.Add(new MailAddress(contact.Email));
                message.Subject = "Thankyou for contacting Tapfreaks";
                message.Body = " Thankyou; this is mail message is send to you, to inform you that your request has been sent to tapfreaks team";
                GlobalController.SendEmail(message);
            }
            catch (Exception ex)
            {
                // Response.Write(ex.Message);

            }
        }
        private void SendEmailToTapfreaks(Contact contact)
        {
            StringBuilder body = new StringBuilder();
            try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress("info@tapfreaks.net");
                message.To.Add(new MailAddress("koheseena@yahoo.com"));
                message.Subject = contact.Name + " Contacted Tapfreaks";

                body.AppendLine("Name = " + contact.Name);
                body.AppendLine("Email = " + contact.Email);
                body.AppendLine("Message = " + contact.Message);
                message.Body = body.ToString();
                GlobalController.SendEmail(message);
            }
            catch (Exception ex)
            {
                // Response.Write(ex.Message);

            }
        }
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(Contact contact)
        {
            SendEmailToTapfreaks(contact);
            SendEmailToClient(contact);
            return View("Thanks");
        }

        [HttpPost]
        public ActionResult Thanks()
        {
            //SendEmail();
            return View();
        }



    }
}
